//引入模型
require('../model/exerciseModel');
require('../model/testsModel');
require('../model/testedModel')
const mongoose = require('mongoose');



//获取所有的考过的试卷
async function getAllExercises(req,res,next) {
    let test=await mongoose.model('testsModel').find({_id:"610bce08a50c00009700644e"}).populate("typeId");
    let testedStu=await mongoose.model('testedModel').find({}).populate("studentId").populate("testId");
    let array=test[0].exercisesId;
    let exercises=[];
    //let exercise =await mongoose.model('exercisesModel').find({}).populate("pointId");
    for(i=0;i<array.length;i++){
        let id=array[i];
        let exercise =await mongoose.model('exercisesModel').find({_id:id}).populate("pointId");
        console.log(exercise);
        exercises.push(exercise);
    }
    // let exe=array.forEach(a => async function() {
    //     console.log(a);
    //     let id=a;
    //     let exercise =await mongoose.model('exercisesModel').find({_id:id}).populate("pointId");
    //     console.log(exercise);
    // });
 
    
    //let array=test.exercisesId;
  
    res.send({exercises, test,testedStu });
}

//getAllExercises();
module.exports = {
    getAllExercises
}